package de.mhus.lib.mandala.table;

import java.util.LinkedList;

import de.mhus.lib.mandala.Component;
import de.mhus.lib.mandala.Response;
import de.mhus.lib.mandala.bind.DataProvider;

public class DynamicTable extends Component {

	private LinkedList<TableColumn> columns = new LinkedList<TableColumn>();
	
	public void addColumn(TableColumn column) {
		columns.add(column);
	}
	
	@Override
	protected void doRender(Response response) {
		response.startTag("table", "table table-striped" , null);
		response.startTag("thead",null,null);
		
		response.startTag("tr",null,null);
		for (TableColumn col : columns) {
			response.startTag("th",null,null);
			col.getHeader().doRender(this, response);
			response.endTag("th");
		}
		response.endTag("tr");
		
		response.endTag("thead");
		response.startTag("tbody",null,this.getTagAttributes());
		
		response.startTag("tr",null,null);
		for (TableColumn col : columns) {
			response.startTag("td",null,null);
			col.getText().doRender(this, response);
			response.endTag("td");
		}
		response.endTag("tr");
		
		response.endTag("tbody");
		response.endTag("table");
	}

}
